package com.example.fang.demodruid.concurrency7;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;

public class Mytest2 {

    public static void main(String[] args) {
        ExecutorService executorService=new ThreadPoolExecutor(3,5,0,
                TimeUnit.SECONDS,new LinkedBlockingDeque<>(1),new ThreadPoolExecutor.AbortPolicy());
        /**
         * abortPolicy 当任务数达到9时,会抛出拒绝执行异常
         * discardPolicy 当任务达到9时，会抛弃最后一个任务
         *
         */
        IntStream.range(0,5).forEach(i->{
            executorService.submit(()->{
                try{
                    Thread.sleep(3000);
                }catch (Exception e){
                    e.printStackTrace();
                }
                IntStream.range(0,1).forEach(j->{
                    System.out.println(Thread.currentThread().getName());
                });
            });
        });
        executorService.shutdown();
    }
}
